package com.qyer.util.log.util;

import java.util.Map;

import com.qyer.util.log.entity.TrackLog;

public class TrackAreaUtil {
	public static String getArea(TrackLog tracklog , Map<String ,String> areaIpMaps1 , Map<String ,String> areaIpMaps2 , Map<String ,String> areaIpMaps3 , Map<String ,String> areaIpMaps4 , Map<String ,String> areaIpMaps5 ){
		String areas ="";
		
		String ip =tracklog.getUserIp();
		
		String[] tmpIps =ip.split("\\.");
		if(tmpIps.length!=4){
			return "" ;
		}
		String tip1=tmpIps[0]+"."+tmpIps[1];
		String tip2=tmpIps[0]+"."+tmpIps[1]+"."+tmpIps[2];
		if(areaIpMaps2.get(tip2)!=null){
			areas=areaIpMaps2.get(tip2);
		}else{
			if(areaIpMaps1.get(tip1)!=null){
				areas=areaIpMaps1.get(tip1);
			}else{
				areas="";
			}
		}
		
		if (areas==null||"".equals(areas)){
			if(areaIpMaps4.get(tip2)!=null){
				areas=areaIpMaps4.get(tip2);
			}else{
				if(areaIpMaps3.get(tip1)!=null){
					areas=areaIpMaps3.get(tip1);
				}else{
					areas="";
				}
			}
		}
		
		areas=areaIpMaps5.get(areaIpMaps5.get(areas))+","+areaIpMaps5.get(areas)+","+areas;
		
		return areas;
	}
}
